#include <iostream>
#include <future>
#include <memory>
#include <thread>

int Add(int x, int y)
{
    std::cout << "into Add" << std::endl;
    return x + y;
}

int main()
{
    //封装任务;
    auto task = std::make_shared<std::packaged_task<int(int, int)>>(Add);

    //获取future对象;
    std::future<int> res = task->get_future();

    //执行任务;
    std::thread thr([task](){
        (*task)(11, 22);
    });

    //获取任务结果:
    std::cout << res.get() << std::endl;
    thr.join();
    return 0;
}